/**
 * 未回复评论页面，用于加载首页，包括左边树和右边主要内容
 * author:caiyl5
 * date:2016年8月31日9:51:22
 */
	var rebackComment = {
		/**
		 * 初始化绑定事件
		 */
		bindEvent:function(){
			$(".title").unbind().on("click",function(){
				//console.log($(this).attr("data-type")+"====="+
				//排序图片
				var down = '<img src="../admin/images/down.png"/>';
				var uap = '<img src="../admin/images/uap.png"/>';
				//排序规则 首先清空所有的图片，然后原先的规则判断
				if ($(this).attr("data-type")=="ASC") {
					$(".waitcallback-uap").html("");
					window.sessionStorage.comment_orderRule="DESC";
					$(this).attr("data-type","DESC");
					$(this).children(".waitcallback-uap").html(down);
				} else {
					$(".waitcallback-uap").html("");
					window.sessionStorage.comment_orderRule="ASC";
					$(this).attr("data-type","ASC");
					$(this).children(".waitcallback-uap").html(uap);
				}
				//保存数据
				window.sessionStorage.comment_orderKey=$(this).attr("id");
				rebackComment.initComment();
			});
			$(".reply-comment-title").unbind().on("click",function(){
				rebackComment.initComment();
			});
		},
		/**
         * 初始化评论列表
	     */
		initComment:function(){
			//转圈
			common.showLoading();
			var param={
				"pk_user":window.localStorage.userid,
				"pageSize":common.pageSize,
				"pageNum":common.currentPage,
				"orderKey":window.sessionStorage.comment_orderKey,
				"orderRule":window.sessionStorage.comment_orderRule
			};
			//请求参数
			var url = "/pc/comment/getNotCommentList";
			common.interfaceAjaxFunction(url,param,rebackComment.queryNotCommentListSuccess);

		},
		/**
         * 查询待回复评论成功回调
	     */
		queryNotCommentListSuccess:function(res){
			$("#tbody").empty();
			//console.log(res);
			var tr_html="";
			//成功时候
	    	if(res.status == "0"){
				if (res.data.length==0) {
					tr_html='<tr><td colspan="5">暂无待回复评论</td></tr>';
					$("#pageDivideContainer").hide();
				} else {

					for (var i = 0; i < res.data.length; i++) {
			        	var comment_time = res.data[i].comment_time;
			        	var comment_contant = res.data[i].comment_contant;
			        	var user_name = res.data[i].user_name;
						if (user_name == undefined || user_name == null) {
							user_name = "";
						}
			        	var publish_title = res.data[i].publish_title;
			        	var pk_publish = res.data[i].pk_publish;
			        	var pk_comment = res.data[i].pk_comment;

				        //每一列
						tr_html += '<tr pk_comment="'+pk_comment+'" pk_publish="'+pk_publish+'">'+
							'<td ><a class="blue-color waitcallback-content comment_contant" >'+comment_contant+'</a></td>'+
							'<td ><a class="blue-color waitcallback-content publish_title">'+publish_title+'</a></td>'+
				            '<td ><span class="waitcallback-content" >'+user_name+'</span></td>'+
				            '<td ><span class="waitcallback-content">'+comment_time+'</span></td>'+
				            '<td><div class="operation" ><a class="operation_reply"  >回复</a></div></td>'+
				        '</tr>';
			        }
				}
	    	}else{
	    		//给出信息提示
	    		common.show_error(res.message);
	    	}

	        $("#tbody").html(tr_html);
	    	//转圈提示去除
	    	common.hideLoading();

			 /**
             * 绑定点击事件
             * window.sessionStorage.rebackComment_publish  未回复的评论的知识id
             * window.sessionStorage.rebackComment_comment  未回复的评论id
             */
			$(".operation_reply").unbind().on("click",function(){
				window.sessionStorage.rebackComment_publish=$(this).parent().parent().parent().attr("pk_publish");
	        	window.sessionStorage.rebackComment_comment=$(this).parent().parent().parent().attr("pk_comment");
				rebackComment.toRebackCommentDetail();
			});
			$(".comment_contant").unbind().on("click",function(){
				//console.log($(this).parent().parent().parent().attr("pk_publish"))
				
				window.sessionStorage.rebackComment_publish=$(this).parent().parent().attr("pk_publish");
	        	window.sessionStorage.rebackComment_comment=$(this).parent().parent().attr("pk_comment");
				rebackComment.toRebackCommentDetail();
			});

			// 弹出新的窗口查看详情
			$(".publish_title").unbind().on("click",function(){
				window.sessionStorage.rebackComment_publish=$(this).parent().parent().attr("pk_publish");
				window.sessionStorage.rebackComment_comment=$(this).parent().parent().attr("pk_comment");
				rebackComment.toKmMaintanceReading();
			});
			//产生分页结构
			common.getPageDivide(res.count,"pageDivideContainer",rebackComment.initComment);
		},
		/**
		 * 跳转到知识详情界面
		 */
		toKmMaintanceReading:function(){
			//console.log($(this).parent().parent().attr("pk_publish"));
			window.open("html/kmMaintanceReading.html?pk_publish="+window.sessionStorage.rebackComment_publish);
		},
		/**
		 * 跳转到回复评论界面
		 */
		toRebackCommentDetail:function(){
			layer.ready(function () {
	                //增加编辑
	               layer.open({
				    type: 2,
				    //skin: 'layui-layer-lan',
				    title: '回复评论',
				    fix: false,
				    shadeClose: true,
				    maxmin: false,
				    area: ['70%', '600px'],
				    // content: 'html/keyIndustryMaintanceChoose.html',
				    content:'html/rebackCommentDetail.html',
				  });
	            });
		},
		initialize : function(){
			//初始化当前页
			common.currentPage=1;
			//默认按时间倒序排序
			window.sessionStorage.comment_orderKey="comment_time";
			window.sessionStorage.comment_orderRule="DESC";
			//绑定事件
			rebackComment.bindEvent();
			//加载第一个页面
			rebackComment.initComment();
		}
	};
	/*$(document).ready(function(){
		//初始化当前页
		common.currentPage=1;
		//默认按时间倒序排序
		window.sessionStorage.comment_orderKey="comment_time";
		window.sessionStorage.comment_orderRule="DESC";
		//绑定事件
		rebackComment.bindEvent();
		//加载第一个页面
		rebackComment.initComment();
	});*/
